function Marker(data, overlay, options) {
	var self = this;
	if(data) {
		self.position = data.position;
		self.title = data.title; 
	} 
	else {
		self.position = [];
		self.title = "Sin titulo";
	}

	if (overlay) {
		self.overlay = overlay;
		$(self.overlay).bind('delete', function() {
			self.onOverlayDelete();
		})
	}

	this.options = options || {};
  
  
}
//TODO
Marker.prototype.onOverlayDelete = function() {
	if(self.gpolyline) {
		self.gpolyline.setMap(null);
	}
}
 

Marker.prototype.to_gmarker = function() {
	var self = this;
	var pos = self.posToGPoint(self.position);
	var gmarker = new google.maps.Marker({
		position: pos
		,title: self.title
		,draggable:true
	});

	if (self.options.click) {
		google.maps.event.addListener(gmarker, 'click', function() {
			self.options.click.call(self.overlay, self);
		});
	  
	}

	return gmarker;
} 

Marker.prototype.posToGPoint = function(pos) {
	return new google.maps.LatLng(pos.latitude, pos.longitude);
}

Marker.prototype.setMap = function(map) {
	if(!this.gmarker) this.gmarker = this.to_gmarker();
	this.gmarker.setMap( map && map.gmap);
} 

Marker.prototype.to_json = function() {
	return {
		position: this.position
		, title: this.title
	};
}








